package leetcode.code0118;

import java.util.ArrayList;
import java.util.List;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	public int[][] pascal_triangle_array(int n) {
		int[][] ans = new int[n][n];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j <= i; j++) {
				if (j == 0 || j == i) {
					ans[i][j] = 1;
				} else {
					ans[i][j] = ans[i - 1][j - 1] + ans[i - 1][j];
				}
			}
		}
		return ans;
	}

	public List<List<Integer>> generate(int numRows) {
		List<List<Integer>> ans = new ArrayList<>();
		int[][] combs = this.pascal_triangle_array(numRows);
		for (int i = 0; i < numRows; i++) {
			List<Integer> row = new ArrayList<>();
			for (int j = 0; j <= i; j++) {
				row.add(combs[i][j]);
			}
			ans.add(row);
		}
		return ans;
	}

	public List<List<Integer>> generate1(int numRows) {
		List<List<Integer>> ans = new ArrayList<>();
		for (int i = 0; i < numRows; i++) {
			List<Integer> row = new ArrayList<>();
			for (int j = 0; j <= i; j++) {
				if (j == 0 || j == i) {
					row.add(1);
				} else {
					row.add(ans.get(i - 1).get(j - 1) + ans.get(i - 1).get(j));
				}
			}
			ans.add(row);
		}
		return ans;
	}

	@Override
	public void debug4() {
		List<List<Integer>> list = this.generate(5);
		for (List<Integer> row : list) {
			H.print(row);
		}

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
